package activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.gongxiangcheng.FlowLayout;
import com.example.administrator.gongxiangcheng.R;
import com.yuyh.library.BubblePopupWindow;


/**
 * Created by Administrator on 2017/3/28.
 */

public class mineSsActivity extends Activity {

    private BubblePopupWindow centerWindow;
    private EditText editText;
    private ImageView imageView,imageView2;
    private FlowLayout flowLayout;
    private TextView textView,textViewqx;
    LayoutInflater inflater;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mine_ss);


         textView = (TextView) findViewById(R.id.xz_tv);
         textViewqx = (TextView) findViewById(R.id.q_x);
         editText = (EditText) findViewById(R.id.ss_et);
         imageView = (ImageView) findViewById(R.id.san_cu_iv);
         imageView2 = (ImageView) findViewById(R.id.xx_iv);
         flowLayout = (FlowLayout) findViewById(R.id.flow_layout);
         centerWindow = new BubblePopupWindow(mineSsActivity.this);
         inflater = LayoutInflater.from(this);
         textView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 View bubbleView = inflater.inflate(R.layout.layout_popup_view, null);
                 centerWindow.setBubbleView(bubbleView);
                 centerWindow.show(v, Gravity.BOTTOM, 0);
                 TextView textView1 = (TextView) bubbleView.findViewById(R.id.zc_tv);
                 TextView  textView2 = (TextView) bubbleView.findViewById(R.id.zx_tv);
                 textView1.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {

                         textView.setText("众筹");
                         centerWindow.dismiss();
                     }
                 });
                 textView2.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View v) {
                         textView.setText("资讯");
                         centerWindow.dismiss();
                     }
                 });



             }
         });

        textViewqx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });


       editText.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
               String  edtx  =  editText.getText().toString();
               if (!TextUtils.isEmpty(edtx)){
                   TextView textView = buildLabel(edtx);
                   flowLayout.addView(textView);
               }

           }
       });
    }



    //流式布局
    private TextView buildLabel(String text) {
        TextView textView = new TextView(this);
        textView.setText(text);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
        textView.setPadding((int) dpToPx(10), (int) dpToPx(6), (int) dpToPx(10), (int) dpToPx(6));
        textView.setGravity(Gravity.CENTER);
        textView.setBackgroundResource(R.drawable.label_bg);
        return textView;
    }
    //dp转换成px
    private float dpToPx(float dp) {
        return TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
    }








}
